package com.czk.date;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.util.Date;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/8/26 16:44
 */
public class LocalDateTimeDemo {
    public static void main(String[] args) {
        LocalDateTime localDateTime = LocalDateTime.of(2014, Month.JULY, 25, 4, 5);
        System.out.println(localDateTime);
        DayOfWeek dayOfWeek = localDateTime.getDayOfWeek();
        int dayOfMonth = localDateTime.getDayOfMonth();
        int dayOfYear = localDateTime.getDayOfYear();
        System.out.println(dayOfWeek);
        System.out.println(dayOfMonth);
        System.out.println(dayOfYear);
        // 获取该天的第几分钟 245
        System.out.println(localDateTime.getLong(ChronoField.MINUTE_OF_DAY));

        Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        Date date = Date.from(instant);
        System.out.println(date);
        DateTimeFormatter formatter =
                DateTimeFormatter
                        .ofPattern("yyyy-MM-dd hh:mm:ss");
        String string = formatter.format(localDateTime);
        System.out.println(string);
    }
}
